#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Copyright (c) 2021 Huawei Device Co., Ltd.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

  http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
"""

import sys
import argparse


LITEOS_M_TARGET_LIST = [
]


def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('--method_name', help='', required=True)
    parser.add_argument('--arguments', help='', required=True)
    args = parser.parse_args()
    this_module = sys.modules[__name__]
    method = getattr(this_module, args.method_name)
    arguments = {}
    for argument in args.arguments.split("#"):
        key_value = argument.strip().split("=")
        if len(key_value) != 2:
            raise ValueError("The arguments format is 'key=value#key=value'."
                             "wrong format: %s" % argument)
        arguments.setdefault(key_value[0].strip(), key_value[1].strip())
    method(**arguments)
    return 0


def get_build_targets(target_name):
    if target_name == "": 
        match_string = ",".join(LITEOS_M_TARGET_LIST)
    else:
        match_string = ",".join(get_matching_elements(LITEOS_M_TARGET_LIST,
                                                      target_name))
    print(match_string)
    return match_string


def get_matching_elements(elements, target):
    match_list = []
    for item in elements:
        if item.split(":")[-1] == target:
            match_list.append(item)
    return match_list


if __name__ == '__main__':
    sys.exit(main())
